package com.example.dataservice.service;

import com.example.api.model.Product;
import com.example.api.pojo.MultiProduct;
import com.example.api.service.PlatBaseInfoService;
import com.example.api.service.ProductService;
import com.example.common.Constans.YLBConstant;
import com.example.common.util.CommonUtil;
import com.example.dataservice.mapper.ProductMapper;
import org.apache.dubbo.config.annotation.DubboService;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @Description：
 * @Author：曹杰克
 * @CreateTime：2024/7/30 10:58
 */
@DubboService(interfaceClass = ProductService.class,version = "1.0")
public class ProductServiceImpl implements ProductService {

    @Resource
    private ProductMapper productMapper;

    /**
     * 按类型分页查询产品
     * @param pType
     * @param pageNo
     * @param pageSize
     * @return
     */
    @Override
    public List<Product> queryByTypeLimit(Integer pType, Integer pageNo, Integer pageSize) {
        List<Product> products = new ArrayList<>();
        if(pType == 0 ||pType == 1 ||pType == 2){
            pageNo = CommonUtil.defaultPageNo(pageNo);
            pageSize = CommonUtil.defaultPageSize(pageSize);
            Integer offset = (pageNo-1)*pageSize;
            products = productMapper.queryByTypeLimit(pType, offset, pageSize);
        }
        return products;
    }
    /**首页多个产品的数据*/
    @Override
    public MultiProduct queryIndexPageProduct() {
        MultiProduct multiProduct = new MultiProduct();
        //新手宝
        List<Product> xinShouBaoProducts = productMapper.queryByTypeLimit(YLBConstant.PRODUCT_TYPE_XINSHOUBAO, 0, 1);
        //优选
        List<Product> youXuanProducts = productMapper.queryByTypeLimit(YLBConstant.PRODUCT_TYPE_YUXUAN, 0, 3);
        //散标
        List<Product> sanBiaoProducts = productMapper.queryByTypeLimit(YLBConstant.PRODUCT_TYPE_SANBIAO, 0, 3);
        multiProduct.setXinShouBao(xinShouBaoProducts);
        multiProduct.setYouXuan(youXuanProducts);
        multiProduct.setSanBiao(sanBiaoProducts);
        return multiProduct;
    }

    @Override
    public Integer queryRecordNumsByType(Integer pType) {
        Integer counts = productMapper.countNumByPType(pType);
        return counts;
    }
}
